package com.mz.ieann.dokit.utils

import android.app.Activity
import android.content.Context
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.Paint
import android.text.TextUtils
import android.util.Log
import android.view.View
import java.io.InputStreamReader
import java.io.LineNumberReader
import java.util.*

/**
 * <p>------------------------------------------------------
 * <p> Copyright (C) 2021 zhangmz, All rights reserved.
 * <p> If there is technical discussion, you can contact zhangmz90@foxmail.com
 * <p>------------------------------------------------------
 * <p> 获得系统属性
 * <p>
 *
 * @author Created by zhangmz
 * @date on 2022/11/28
 */
object AttribUtil {

    /**
     * 获得有线mac地址，mac地址为空则取uuid
     */
    fun getMac(): String{
        var macSerial: String? = null
        var macAddress: String? = null
        var input: LineNumberReader? = null
        try {
            val pp = Runtime.getRuntime().exec("cat /sys/class/net/eth0/address")
            val ir = InputStreamReader(pp.inputStream)
            input = LineNumberReader(ir)
            if (input.readLine().also { macAddress = it } != null) {
                macSerial = macAddress!!.trim { it <= ' ' }
            }
        }catch (e: Exception){
            e.printStackTrace()
        }finally {
            runCatching {
                input?.close()
            }
        }
        val macId = macSerial?.replace(":".toRegex(), "")
        Log.v("aaaaa", "getMac,macId:$macId")
        return if (TextUtils.isEmpty(macId)) UUID.randomUUID().toString() else macId?: ""
    }

    fun pageGrey(context: Activity){
        val colorMatrix = ColorMatrix()
        colorMatrix.setSaturation(0.0f)
        val paint = Paint()
        paint.colorFilter = ColorMatrixColorFilter(colorMatrix)
        context.window.decorView.setLayerType(View.LAYER_TYPE_HARDWARE, paint)
    }

}